package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.OperateLog;
import com.itheima.entity.PageBean;
import com.itheima.mapper.OperateLogMapper;
import com.itheima.service.OperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperateLogServiceImpl implements OperateLogService {
    @Autowired
    private OperateLogMapper operateLogMapper;

    /**
     * 日志分页查询--使用分页插件
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageBean logPage(Integer page, Integer pageSize) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);

        //2.调用mapper查询分页列表
        List<OperateLog> list = operateLogMapper.list();
        Page<OperateLog> p = (Page<OperateLog>) list;

        //3.构造PageBean对象并返回
        return new PageBean(p.getTotal(), p.getResult());
    }
}
